package com.wdl.fmnew.core.mvp.rxlife.impl;

import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;

import com.trello.rxlifecycle2.LifecycleTransformer;
import com.trello.rxlifecycle2.RxLifecycle;
import com.wdl.fmnew.core.mvp.rxlife.RxLifeEvent;

import io.reactivex.Observable;
import io.reactivex.subjects.BehaviorSubject;

/**
 * Created by wdl on 2017/9/18.
 */

public class BaseRxLifePresenter {

    private final BehaviorSubject<RxLifeEvent> lifecycleSubject = BehaviorSubject.create();


    @NonNull
    @CheckResult
    public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull RxLifeEvent event) {
        return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
    }


    protected void onDestory() {
        lifecycleSubject.onNext(RxLifeEvent.DESTROY);
    }
}
